class RolesController < ApplicationController
  before_filter :isCompanyOwner, :expect => []
  before_filter :isNotCompanyOwner, :only => []
  #private
  def edit
    @roles = Role.where(:company_id => current_user.company_pid)
    #render :layout => nil 
  end
  
  def update    
    if(params != nil && params.length != 0)
      @roles = Role.where(:company_id => current_user.company_pid)
      Role.columns.each do |c|
        next if c.type!=:boolean
        @roles.each do |role|
          next if Rolename.find_by_id(role.rolename_id).id==4
          name = Rolename.find_by_id(role.rolename_id).name
          next if ( params[name]==nil or params[name].length==0 )
          if params[name][c.name]
            role.update_attributes(c.name=>true)
          else
            role.update_attributes(c.name=>false)
          end 
        end
      end
      redirect_to :action => :show
    else
      redirect_to :action => :edit
    end
  end
  
  def show
    @roles = Role.where(:company_id => current_user.company_pid)
    #render :layout => nil
  end
end